@extends('admin.layouts.master')
@section('css')
    <link rel="stylesheet" href="{{asset('/css/admin/commodity_edit.css')}}">
@endsection
@section('content')
    @include('admin.layouts.message')
    {{--表头--}}

    <div class="main_header clearfix">

        <div class="main_header_show clearfix">
            <span><a style="color:white;font-size: 18px" href="{{url('/admin/commodity')}}">商品管理</a><span style="color:white;font-size: 18px">&nbsp;&nbsp;>&nbsp;&nbsp;商品详情</span></span>
        </div>
        <div class="main_header_edit clearfix">
            @if(Auth::guard('admin')->user()->checkPermission('goods.edit'))
            <div class="add_box clearfix" data-toggle="modal" data-target="#myModal">
                <img src="{{asset('images/update_icon.png')}}" alt="">
                <span>编辑</span>
            </div>
            @endif
        </div>
    </div>
    {{--主要的内容区上半部分--}}
    <div class="main_form clearfix">
        <!-- 编辑区 -->
        <div class="main_infolist clearfix">
            <div class="main_editarea clearfix">
                <img style="width:148px;height:148px" src="{{asset($datas['img'])}}" alt="">
                <div class="peson_infolist clearfix">
                    <div class="peson_left clearfix" style="overflow: hidden;">

                        <li>
                            <span>商品类型&nbsp;:</span>
                            <span>{{$datas['class_name']}}</span>
                        </li>
                        <li>
                            <span>商品名称&nbsp;:</span>
                            <span>{{$datas['name']}}</span>
                        </li>
                        <li>
                            <span>产&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;地&nbsp;:</span>
                            <span>{{$datas['area']}}</span>
                        </li>
                        <li>
                            <span>生产日期&nbsp;:</span>

                            <span>{{$datas['product_at']}}</span>
                        </li>
                        <li>
                            <span>保&nbsp;&nbsp;质&nbsp;&nbsp;期&nbsp;:</span>
                            <span>{{$datas['productdate']}}</span>
                        </li>
                        <li>
                            <span>添加日期&nbsp;:</span>

                            <span>{{$datas['created_at']}}</span>
                        </li>
                    </div>
                    <div class="peson_right" style="overflow: hidden;">
                        <li>
                            <span>加工企业&nbsp;:</span>

                            <span style="overflow: hidden;">{{$datas['work_company']}}</span>
                        </li>
                        <li>
                            <span>产&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;址&nbsp;:</span>

                            <span style="overflow: hidden;">{{ $datas['site']}}</span>
                        </li>
                        <li>
                            <span>数&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;量&nbsp;:</span>
                            <span>{{ $datas['nums']}}</span>
                        </li>
                        <li>
                            <span>商品单价&nbsp;:</span>
                            <span>{{ $datas['price']}}</span>
                        </li>
                        <li>
                            <span>商品编号&nbsp;:</span>

                            <span style="overflow: hidden;">{{$datas['product_code']}}</span>
                        </li>
                        <li>
                            <span>上架状态&nbsp;:</span>
                            <span>

                                @if($datas['status']==1)
                               <span style="color:red;">上架中</span>
                                    @else
                                <span style="color: green;">已上架</span>
                                @endif
                            </span>
                        </li>
                    </div>
                </div>
            </div>
        </div>
    </div>
            <!-- RFID列表 -->

            <div class="rfid_header clearfix">
                    <div class="rfid_list_style">
                        <span>RFID列表</span>
                    </div>
                   {{--RFID导入--}}
                   <div class="rfidin_list clearfix">
                       @if(Auth::guard('admin')->user()->checkPermission('goods.create'))
                    <div class="rfidin_box clearfix" onmouseover="this.style.cursor='hand'" style="margin-top: -5px;">
                        <form action="" method="post" enctype="multipart/form-data" id="formlist">
                            {{csrf_field()}}
                             <input type="file" name="excel"  id="fileinput" data-id="{{$datas['id']}}"  style="position: absolute;width: 90px;height: 40px;opacity: 0;
                              -ms-filter: 'alpha(opacity=0)';cursor:pointer;" value=""   onchange="fileupload()" multiple="multiple">
                            <img src="{{asset('images/lodingin_icon.png')}}" alt="">
                            <span style=" color: orange">导入</span>
                        </form>
                    </div>
                       @endif

                           @if(Auth::guard('admin')->user()->checkPermission('goods.create'))
                               <form action="" method="post" enctype="multipart/form-data">
                                   {{csrf_field()}}
                       <div class="rfidin_box  clearfix" style=" border: 1px solid #24a7f6; margin-top: -5px;">
                           <span onclick="downloadExcel()">模板下载</span>
                       </div>
                               </form>
                           @endif

               </div>
            </div>


            <!-- 订单详情表格 -->
            <div class="main_formlist clearfix">
                <div class="form_list clearfix">
                <table class="table table-bordered main_table">
                    <tbody>
                    <tr>
                        <th>RFID码</th>
                        <th>出售状态</th>
                        <th>添加时间</th>
                    </tr>
                    @foreach($rfid_lists as $rfid_list)
                      <tr>
                          <td>{{$rfid_list->rfid}}</td>
                          <td>
                              @if($rfid_list->state==0)
                                  <span style="color: red;">未购买</span>
                              @else
                                  <span style="color: green;">已出售</span>
                              @endif
                          </td>
                          <td>{{$rfid_list->created_at}}</td>
                      </tr>
                    @endforeach
                    </tbody>
                </table>
            </div>

            <div class="boot_fenye">
                <div class="boot_page">
                    <div class="boot_page_di">第<span class="">{{ $page = isset($_GET['page'])?$_GET['page']:1}}</span>页
                    </div>
                    <div  class="boot_page_total">共<span>{{$total_page}}</span>页
                    </div>
                <div class="boot_choose">
                    {{$rfid_lists->links()}}
                </div>
            </div>
        </div>
            </div>
@endsection
<!-- Modal -->
<div style="display: none;margin-top: 100px;" class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header" style="background: #3D446B;">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close" style="color: white;"><span aria-hidden="true"><img
                                src="{{asset('/images/cancel_icon.png')}}" alt=""></span></button>
                <h4 class="modal-title" id="myModalLabel" style="color: white;text-align: center; font-size: 24px;">编辑</h4>
            </div>
            <form  id="addForm" action="" enctype='multipart/form-data' method="post">
                {{csrf_field()}}
                <div class="modal-body">
                    <div class="modal_info clearfix">
                        <div class="modal_info_left">
                    <p class="blinfo"><span>商品类型</span><br>

                        {{--<input type="text" name="class_id" value="{{ $goods->class_id}}">--}}
                        <select name="class_id" class="form-control" style="margin-top: 7px; border-radius: 0px;">
                            <option value="0">顶级分类</option>
                            @include('admin.goods_class_option',['goodsClasses'=>$goodsClasses,'targetClassId'=>$targetClassId,'sign'=>'&nbsp;&nbsp;&nbsp;&nbsp;'])
                        </select>

                    </p>

                    <p class="blinfo"><span>商品名称</span><br>
                        <input type="text" name="name" value="{{$datas['name']}}"></p>
                            {{--@if(count($errors) > 0)--}}
                                {{--<div class="" style="color: red;width: 400px;">{{$errors->first('goods_name')}}</div>--}}
                            {{--@endif--}}

                    <p class="blinfo"><span>产地</span><br>
                        <input type="text" name="area" value="{{$datas['area']}}"></p>

                    <p class="blinfo"><span>生产日期</span><br>

                            <div class='input-group date' id='datetimepicker1' style="width: 233px;">
                                <input type='text' class="form-control" name="product_at" value="{{$datas['product_at']}}" />
                                <span class="input-group-addon">
                    <span class="glyphicon glyphicon-calendar"></span>
                </span>

                            </div>
                            </p>
                    <p class="blinfo"><span>*保质期</span><br>
                        <input type="text" name="productdate" value="{{$datas['productdate']}}"></p>
                            {{--@if(count($errors) > 0)--}}
                                {{--<div class="" style="color: red;width: 400px;">{{$errors->first('productdate')}}</div>--}}
                            {{--@endif--}}
                        </div>
                        <div class="modal_info_right">
                    <p class="blinfo"><span>加工企业</span><br>
                        <input type="text" name="work_company" value="{{$datas['work_company']}}"></p>

                    <p class="blinfo"><span>产址</span><br>
                        <input type="text" name="site" value="{{$datas['site']}}"></p>

                    <p class="blinfo"><span>*商品单价</span><br>
                        <input type="text" name="price" value="{{$datas['price']}}"></p>
                            {{--@if(count($errors) > 0)--}}
                                {{--<div class="" style="color: red;width: 400px;">{{$errors->first('price')}}</div>--}}
                            {{--@endif--}}

                    <p class="blinfo"><span>*商品编号</span><br>
                            <input type="text" name="product_code" value="{{$datas['product_code']}}"></p>
                            {{--@if(count($errors) > 0)--}}
                                {{--<div class="" style="color: red;width: 400px;">{{$errors->first('product_code')}}</div>--}}
                            {{--@endif--}}
                            {{--<span  style="color: red">{{session('codeFails')}}</span>--}}
                     <p class="blinfo"><span>*更换图片</span><br>

                         <a href="javascript:void(0);" class="a-upload" style="text-decoration:none;margin-top: 10px;padding-bottom: 10px;">
                                <input type="file" name="img" value="{{$datas['img']}}"><span>图片</span>
                         </a></p>
                    </div>
                </div>
             </div>
                {{--样式的保持--}}
                 <span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>
                <div class="modal-footer" style="text-align: center;">
                    <button id="save"  type="button"  class="btn btn-primary" style="height:40px;border: 0px solid;width: 300px;background: #2BAAF7" >
                        修改</button>
                </div>
            </form>
        </div>
    </div>
</div>
@section('js')
        {{--表单提交--}}
            <script>
                $("#save").on("click",function () {
                    $("#addForm").ajaxSubmit({
                        url:"{{url('/admin/commodity/update/'.$datas['id'])}}" ,
                        dataType: 'json',
                        data: $('#addForm').serialize(),
                        type: 'post',
                        success: function (res) {
                            if (res.status == 0) {
                                layer.msg(res.msg);
                            } else {
                                layer.msg(res.msg, {icon: 1}, function () {
                                    location.href = "{{url('/admin/commodity/show/'.$datas['id'])}}";
                                });
                            }
                        }
                    })
                })
            </script>
    <script>
        //bootstrap-日历控件js
        $(function () {
            $('#datetimepicker1').datetimepicker({
                language: 'zh-CN',//显示中文
                format: 'yyyy-mm-dd ',//显示格式
                minView: "month",//设置只显示到月份
                initialDate: new Date(),//初始化当前日期
                autoclose: true,//选中自动关闭
                todayBtn: true//显示今日按钮
            });
            $('#datetimepicker2').datetimepicker({
                language: 'zh-CN',//显示中文
                format: 'yyyy-mm-dd',//显示格式
                minView: "month",//设置只显示到月份
                initialDate: new Date(),//初始化当前日期
                autoclose: true,//选中自动关闭
                todayBtn: true//显示今日按钮
            });
        });
        //rfid导入  提交表单
        //rfid信息导入成功
        function fileupload(){
            $('#formlist').ajaxSubmit({
//                ['goods_id'=>$good->id]
                url: "{{url('admin/commodity/rfidimport/'.$datas['id'])}}",
                dataType:'json',
                type:'post',
                data:$('#formlist').fieldSerialize(),
//                data:$('#formlist').serialize(),
                success:function(res) {
                    var input = document.getElementById('fileinput');
                    input.value='';
                    if (res.status == 0) {
                        layer.msg(res.msg);
                    } else {
                        layer.msg(res.msg, {icon: 1}, function () {
                            location.reload();
                            {{--location.href = "{{url('/admin/commodity/show/'.$goods->id)}}";--}}
                        });
                    }


                },
                error:function(xhr, type){
                    layer.msg('请检查导入的excel表格式是否正确');
                    var input = document.getElementById('fileinput');
                    input.value='';
                }
            });
        }
        //模板下载
        function downloadExcel(){
            //获取服务器地址
            var host = location.host;
            //把excel发送出来
            var url = "http://"+ host +"/admin/commodity/rfiddownload";
            window.open(url);
        }
   </script>
@endsection
